﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.Sample.Domain.Model;
using Framework.UnitOfWork;
using Microsoft.Practices.Unity;
using Framework.Sample.Command.AccountCommands;
using Framework.Command;
using Framework.Bus;
using Framework.Infrastructure;

namespace Framework.Sample.WebTest.Controllers
{
    public class FrameworkController : Controller
    {
        ICommandBus _commandBus;

        public FrameworkController(ICommandBus commandBus)
        {
            _commandBus = commandBus;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult EventBusTest()
        {
            var command = new RegisterAccount
            {
                AccountName = "Ivan",
                Age = 30,
                Password = "1234"
            };
            _commandBus.Send(command);
            return View((object)Server.HtmlEncode(string.Format("{0}", command.Response)));

            //var changePasswordCmd = new ChangePassword
            //{
            //    Password = DateTime.Now.ToString(),
            //    AccountID = 5
            //};
            //dynamic result = null;
            //_commandBus.Send<dynamic>(changePasswordCmd, (response) =>
            //{
            //    result = response;
            //});
            //return View((object)Server.HtmlEncode(string.Format("{0} {1}", result.Success, result.Msg)));
        }
    }
}
